<template>
  <div>
    <!-- 一条文章单元格 -->
    <van-cell>
      <!-- 标题区域的插槽 -->
      <template #title>
        <div class="title-box">
          <!-- 标题 -->
          <span>{{articleItem.title}}</span>
          <!-- 单图片 -->
         <img v-if="articleItem.cover.type == 1" class="thumb" v-lazy="articleItem.cover.images[0]">
        <!-- <van-image class="thumb" v-if="articleItem.cover.type == 1"  lazy-load :src="articleItem.cover.images[0]"> -->
            <!-- <template v-slot:error>加载失败</template> -->
            <!-- 加载中提示 -->
             <!-- <template v-slot:loading>
                <van-loading type="spinner" size="20" />
              </template> -->
          <!-- </van-image> -->
        </div>
        <!-- 三图片 -->
        <div class="thumb-box" v-if="articleItem.cover.type > 1">
          <img v-for="imgUrl in articleItem.cover.images" class="thumb" v-lazy="imgUrl">
          <!-- <van-image v-for="imgUrl in articleItem.cover.images" class="thumb"  lazy-load :src="imgUrl"> -->
           <!-- <template v-slot:error>加载失败</template>
             <template v-slot:loading>
                <van-loading type="spinner" size="20" />
              </template>
          </van-image> -->
        </div>
      </template>
      <!-- label 区域的插槽 -->
      <template #label>
        <div class="label-box">
          <div>
            <!-- <span>{{articleItem.aut_name}}</span> &nbsp;&nbsp; -->
            <span>测试号</span> &nbsp;&nbsp;
            <span>{{articleItem.comm_count}}评论</span> &nbsp;&nbsp;
            <span>{{formatter(articleItem.pubdate)}}</span> &nbsp;&nbsp;
          </div>
          <!-- 反馈按钮 -->
          <van-icon name="cross" @click.stop="show = true" v-if="isShow"/>
        </div>
      </template>
    </van-cell>
    <!-- 动作面板组件 -->
    <van-action-sheet v-model="show" :actions="actions" @select="onSelect" get-container="body" :cancel-text="bottomText" @cancel="canelFn" @closed="closeFn"/>
  </div>
</template>

<script>
  import {
    timeAgo
  } from '@/utils/dayformate.js'
  import {
    firstActions,
    secondActions
  } from '@/api/report.js'
  export default {
    name: 'ArticleItem',
    props: {
      articleItem: {
        type: Object,
        default: {}
      },
      isShow:{
        type:Boolean,
        default:true
      }
    },
    data() {
      return {
        show: false, // 控制下拉框的显示与隐藏
        // 下拉框的配置项
        actions: firstActions, // 反馈面板数组(里面是对象)
        bottomText: '取消',
      }
    },
    methods: {
      // 复制操作
      formatter: timeAgo,
      // 点击弹起下拉框事件
      onSelect(obj, index) {
        // 默认情况下点击选项时不会自动收起
        // 可以通过 close-on-click-action 属性开启自动收起
        // 接收2个参数,当前对象,当前对象的索引
        // console.log(obj)
        if (obj.name == "反馈垃圾内容") {
          this.actions = secondActions // 替换action配置项数组内容
            this.bottomText = '返回' // 修改文字内容
        }else if(obj.name == '不感兴趣'){
            this.$emit('disLikes',this.articleItem.art_id)
            this.show = false
        }else{ // 进入这里证明点击的是二级数组(反馈垃圾内容)
           this.$emit('reports',this.articleItem.art_id,obj.value)
           this.show = false // 替换为一级数组的事情让 closeFn 函数帮我们做
        }
      },
      // 点击取消按钮触发的事件
      canelFn(){
       if(this.bottomText == '返回'){
         this.show = true // 让弹框不消失
         this.actions = firstActions // 替换action配置项数组内容
          this.bottomText = '取消' // 修改文字内容
       }
      },
      // 弹出框消失时触发
      closeFn(){
        this.actions = firstActions // 替换action配置项数组内容
         this.bottomText = '取消' // 修改文字内容
      }
    },
  }
</script>

<style scoped lang="less">
  /* 标题样式 */
  .title-box {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
  }

  /* label描述样式 */
  .label-box {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  /* 文章信息span */
  .label-box span {
    margin: 0 3px;

    &:first-child {
      margin-left: 0;
    }
  }

  /* 图片的样式, 矩形黄金比例：0.618 */
  .thumb {
    width: 113px;
    height: 70px;
    background-color: #f8f8f8;
    object-fit: cover;
  }

  /* 三图, 图片容器 */
  .thumb-box {
    display: flex;
    justify-content: space-between;
  }
    .content {
      padding: 16px 16px 160px;
    }
</style>
